
<template>
  <div>
  <div class="container">
    <div class="player">
      <video-player  class="video-player vjs-custom-skin"
                     ref="videoPlayer"
                     :playsinline="true"
                     :options="playerOptions"
                     @play="onPlayerPlay($event)"
                     @pause="onPlayerPause($event)"
                     :poster="mvId.cover"

      >
      </video-player>
    </div>
  </div>
    <div class="text">
    <p>{{mvId.name}}</p>
      <div class="share">
        <img :src="mvId.cover" ><span>网易云视频</span>
        <van-icon name="good-job-o" size="25"  class="zan" @click="toggle_like()" :class="{liked:liked}" />
        <van-icon name="comment-o" size="25"  class="ping"/>

        <van-icon name="share-o" size="25" @click="showShare = true" class="zhuan"/>
<!--        <van-cell title="" @click="showShare = true" />-->
        <van-share-sheet
            v-model="showShare"
            title="立即分享给好友"
            :options="options"
            @select="onSelect"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { videoPlayer } from 'vue-video-player';
import {getMvCdn} from "@/api/api-MV";
import { Toast } from 'vant';
export default {
  name:"MvList",
  props:{
    mvList:Array,
    mvId:Object,
    // mvId:Object,
  },
  data () {
    return {
      mvSrc:null,
      open:false,
      showShare: false,
      //点赞
      like_count: 10,
      liked: false,
      //视频
      options: [
        { name: '微信', icon: 'wechat' },
        { name: '微博', icon: 'weibo' },
        { name: '复制链接', icon: 'link' },
        { name: '分享海报', icon: 'poster' },
        { name: '二维码', icon: 'qrcode' },
      ],

      playerOptions: {
       playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
        autoplay: false, //如果true,浏览器准备好时开始回放。
        muted: false, // 默认情况下将会消除任何音频。
        loop: false, // 导致视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
            {
          // type: "video/mp4",
          // src: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" //你的视频地址（必填）
          // src:"http://vodkgeyttp8.vod.126.net/cloudmusic/obj/core/3881708987/7d2f78e4feef9915d75509319fc2d3e5.mp4?wsSecret=05ffa7978cdc54e551a39ae92643c485&wsTime=1606218944"
          // src:"'" + this.mvSrc + "'"
        }
        ],
        // poster: "mvId.cover", //你的封面地址
        width: document.documentElement.clientWidth,
        notSupportedMessage: '努力中加载中💪', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
       controlBar: {
         timeDivider: true,
         durationDisplay: true,
         remainingTimeDisplay: false,
         fullscreenToggle: true  //全屏按钮
       }
      }
    }
  },
  created(){
    console.log(this.mvId)
    getMvCdn(this.mvId.id).then(res=>{
      // console.log(res)
      // console.log(res.data.url)
      // debugger
      let obj = {
        type: "video/mp4",
        src:res.data.url
      }
      this.playerOptions.sources.push(obj)

    })
  },
  components: {
    videoPlayer
  },
  methods: {
    //分享页面
    onSelect(option) {
      Toast(option.name);
      this.showShare = false;
    },

    onPlayerPlay() {
      // alert("play");
      this.$emit('son', !this.open)
      console.log(12345)
    },
    onPlayerPause(){
      // alert("pause");
    },
    toggle_like: function () {
      // 如果liked为false 则like_count++ 并把liked取反
      if (!this.liked) {
        this.like_count++
      } else {
        // liked 为true时 like_count-- 并把liked取反
        this.like_count--
      }
      this.liked = !this.liked //把liked取反
    }

  },
  computed: {
    player() {
      return this.$refs.videoPlayer.player
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style type="text/css" scoped>
.container {
  background-color:black;
  min-height: 100%;

}
.player{
  width: 90%;
  margin: auto;

}
p{
  font-size: large;
  /*width: 70%;*/
  /*-webkit-box-orient: vertical;*/
  /*height: 44px;*/
  /*line-height: 22px;*/
  /*overflow: hidden;*/
  /*text-overflow: ellipsis;*/
  /*display: -webkit-box;*/
  /*-webkit-line-clamp: 2;*/
  display: block;
}
.text{
  /*display: flex;*/
  /*justify-content: space-around;*/
  /*justify-content: center*/

}
.share{
  display: flex;
  margin-left: auto;
  margin-bottom: 6px;
  margin-top: -5px;
  /*justify-content: right;*/
  /*margin: auto;*/
}
.ping{

  margin-right: 7px;
}
.zhuan{
  /*margin-right: auto;*/
  margin-right: 7px;
}
.share img{
  width: 25px;
  height: 25px;
  border-radius: 50%;
}
.zan{
  margin-left: auto;
  margin-right: 7px;
}
.liked {
  color: orange;
}
</style>